var hkey_root, hkey_path, hkey_key;
hkey_root = "HKEY_CURRENT_USER";
hkey_path = "\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";

//网页打印时清空页眉页脚
function pagesetup_null() {
	try {
		var RegWsh = new ActiveXObject("WScript.Shell");
		hkey_key = "header";
			RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "");
			hkey_key = "footer";
				RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "");
	} catch (e) {
	}
}

//网页打印的时恢复页眉页脚为默认值
function pagesetup_default() {
	try {
		var RegWsh = new ActiveXObject("WScript.Shell");
		hkey_key = "header";
			RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "&w&b页码，&p/&P");
			hkey_key = "footer";
				RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "&u&b&d");
	} catch (e) {
	}
}
function getPrintHtml(url,parmas,title){
	var strHtml = "";
    $.post(url,parmas,function (data) {
        strHtml +=  "<style type='text/css'>.table{width: 100%; text-align: left; font-size: 12px; font-family: arial;  border-collapse: collapse;}.table th{ padding: 4px 3px 4px 5px; border: 1px solid #d0d0d0;  " +
        		"border-left-color: #eee; background-color: #ededed; font-weight: bold;}  .table td{padding: 4px 3px 4px 5px; border-style: none solid solid; border-width: 1px;  border-color: #ededed;} .table .titleStyle{ border: 1px #ededed solid; " +
        		" font-weight: bolder; text-align: center; font-size: 14px;} .alterbg{ background: #dbe4f3;} </style>" ;
        if (data != null && data.items.length>0) {
            strHtml += "<div><table class='table'>" ;
            strHtml += "<tr>" ;
            strHtml += "<td class='titleStyle' colspan='" ;
            var temNum = 0;
            $.each(data.items[temNum], function (key, value) {
                temNum++;
            });
            strHtml += temNum ;
            strHtml += "'>" ;
            strHtml += "</td>" ;
            strHtml += "</tr>" ;
            strHtml += "<tr>" ;
            $.each(data.header, function (key, value) {
                strHtml += "<th>" ;
                if(value==null|| value=="undefined"){
                }
                strHtml += value ;
                strHtml += "</th>" ;
            });
            strHtml += "</tr>" ;
            for (var i = 0; i < data.items.length; i++) {
                if (i % 2 == 1) {
                    strHtml += ("<tr class='alterbg'>");
                    $.each(data.items[i], function (key, value) {
                        strHtml += "<td>" ;
                        if(value==null||value=="undefined"){
                        	strHtml += "";
                        }else{
                        strHtml += value;
                        }
                        strHtml += "</td>" ;
                    });
                    strHtml += "</tr>" ;
                } else {
                    strHtml += "<tr>" ;
                    $.each(data.items[i], function (key, value) {
                        strHtml += "<td>" ;
                        if(value==null||value=="undefined"){
                        	strHtml += "";
                        }else{
                        strHtml += value;
                        }
                        strHtml += "</td>" ;
                    });
                    strHtml += "</tr>" ;
                }
            }
            strHtml += "</table></div>" ;
        } else {
            strHtml += "暂无数据" ;
        }
    	doPrint(strHtml,title);
    }, 'json');
}
function doPrint(printDiv,title) {
	try {
		pagesetup_null();
		newwin = window.open("", "newwin", "height=" + window.screen.height + ",width=" + window.screen.width + ",toolbar=no,scrollbars=auto,menubar=no,left=0,top=0");
		var pageHtml = "<html><head><title>"+title+"</title>";
		//var pageHtml="<meta http-equiv='X-UA-Compatible' content='IE=8' /><meta http-equiv='Content-Type' content='text/html; charset=utf-8' />";
		//pageHtml+="<link type='text/css' rel='stylesheet' href='"+systemConstants.CONTEXT_PATH +"/css/reportTemplate.css' media='screen,print'>";
		//pageHtml+="<style type='text/css'>ul,li,img,span,p,font,em,ol,h1,h2,h3,h4,dl,dt,dd,input{margin:0; padding:0; border:0; list-style:none;}.rtTable{border-style: none; border-collapse: collapse; border: 0px;}.rtTable tr{border-collapse: collapse;}.rtTable td p{padding-left:35px;}.rtTable_td{ text-align:center;border:1px solid #000; }.rtTable_td input[type=text]{width:100%;text-align:center;}.rtTable_td input{ vertical-align: middle; }.rtTable_td span{vertical-align: middle;}.content_line{width:30%;text-align:center;font-size:24px;font-family:宋体;border-bottom:1px solid #000; }</style>";
		pageHtml+="</head><body>";
		pageHtml += printDiv;
		pageHtml += "</body></html>";
		newwin.document.body.innerHTML = pageHtml;
		newwin.window.print();
		newwin.window.close();
		pagesetup_default();
	} catch (e) { }
}